<?php defined( '_VALID_MOS' ) or die( 'Restricted access' );?>
<form action="index2.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
<script language="JavaScript" type="text/javascript">
<!--
  function formatFloat(id)
  {
      var cur = document.getElementById(id).value;
      reg = /[^\d\.]+/;
      cur = cur.replace(',', '.');
      cur = cur.replace('..', '.');
      cur = cur.replace(reg, '');
      document.getElementById(id).value = cur;
  }
  function formatInt(id)
  {
      var cur = document.getElementById(id).value;
      reg = /[^\d]+/;
      //cur = cur.replace(',', '.');
      //cur = cur.replace('..', '.');
      cur = cur.replace(reg, '');
      document.getElementById(id).value = cur;
  }
  function jcsShowComParams(cparam)
  {
    cbox = document.getElementById("check_" + cparam).checked;
    if(cbox)
    {
      document.getElementById("params_" + cparam).style.visibility='visible';
      document.getElementById("params_" + cparam).style.display='block';
    }
    else
    {
      document.getElementById("params_" + cparam).style.visibility='hidden';
      document.getElementById("params_" + cparam).style.display='none';
    }
  }
function submitbutton(pressbutton, section) {

    var form = document.adminForm;
    if (pressbutton == 'cancel') {
        submitform( pressbutton );
        return;
    }
    
    
    if ( form.name.value == "" ) {
        alert("Name mast be set");
    } else if (form.catid.value == "") {
        alert("Category mast be set");
    } else if (form.days.value == "") {
        alert("Period mast be set");
    } else {
    <?php getEditorContents( 'editor1', 'description' ) ; ?>
    submitform(pressbutton);
    }
}
//-->
</script>
<TABLE width="100%" cellpadding="0" cellspacing="3" border="0">
  <TR valign="top">
    <TD width="55%">
    
        <table class="adminform">
        <tr>
          <th colspan="2">Subscription <?php echo $row->id ? "Edit" : "New" ?></th>
        </tr>
        <tr>
          <td width="150px">Name: </td>
          <td><input type="text" name="name" size="40" value="<?php echo $row->name;?>"></td>
        </tr>
        <tr>
          <td width="150px">Category: </td>
          <td><?php echo $lists['catid'];?></td>
        </tr>
        <tr>
          <td>Time Limit:</td>
          <td><input type="text" name="days" id="days" onkeyup="formatInt('days')" size="5" value="<?php echo $row->days;?>">
          <SELECT name="days_type">
            <OPTION value="days"<?php if ($row->days_type == 'days') echo ' selected="selected" '; ?>>Days</OPTION>
            <OPTION value="weeks"<?php if ($row->days_type == 'weeks') echo ' selected="selected" '; ?>>Weeks</OPTION>
            <OPTION value="months"<?php if ($row->days_type == 'months') echo ' selected="selected" '; ?>>Months</OPTION>
            <OPTION value="years"<?php if ($row->days_type == 'years') echo ' selected="selected" '; ?>>Years</OPTION>
          </SELECT>
          </td>
        </tr>
        <tr>
          <td>Times Limit:</td>
          <td><input type="text" id="tml" onkeyup="formatInt('tml')" name="time_limit" size="40" value="<?php echo $row->time_limit;?>"></td>
        </tr>
        <tr>
          <td>Price:</td>
          <td><input type="text" id="prs" onkeyup="formatFloat('prs')" name="price" size="40" value="<?php echo $row->price;?>"></td>
        </tr>
        <tr>
          <td>Next Time Discount(%):</td>
          <td><input type="text" name="discount" id="dsk" onkeyup="formatFloat('dsk')"  size="40" value="<?php echo $row->discount;?>"></td>
        </tr>
        <tr>
          <td>Article Individualization:</td>
          <td><input type="checkbox" name="type_article" value="1" <?php if ($row->type_article) echo ' checked="checked" '; ?>></td>
        </tr>
        <tr>
          <td>User Individualization:</td>
          <td><input type="checkbox" name="type_user" value="1"<?php if ($row->type_user) echo ' checked="checked" '; ?>></td>
        </tr>
        <tr valign="top">
          <td>Restrict Content Categories:</td>
          <td>
            <?php
              $ctegs = explode(",", $row->category);
              if($ctegs){
                  foreach($ctegs AS $ct)
                  {
                      $selected[]->id = $ct;
                  }
              }
              
              $query = "SELECT id, name FROM `#__sections`";
              $database->setQuery( $query );
              $sect = $database->loadObjectList();
              $category[] = mosHTML::makeOption( '', '- none -', 'id', 'status' );
              foreach($sect AS $sec)
              {
                  $query = "SELECT id, name FROM `#__categories` WHERE `section` = $sec->id";
                  $database->setQuery( $query );
                  $catg = $database->loadObjectList();
                  if(count($catg) <= 0) continue;
                  foreach($catg AS $cat)
                  {
                      $category[] = mosHTML::makeOption( $cat->id, $sec->name.'/'.$cat->name, 'id', 'status' );
                  }
              }
              echo mosHTML::selectList( $category, 'category[]', 'class="inputbox" size="7"  multiple="true" ', 'id', 'status', $selected);
            
            ?>
          </td>
        </tr>
        <tr valign="top">
          <td>Restrict Components:</td>
          <td>
            <?php
        
              $comps = explode(",", $row->component);
              //print_r($comps);
              $query = "SELECT `option`, name FROM `#__components` WHERE parent = 0";
              $database->setQuery( $query );
              $comp = $database->loadObjectList();
              $params = explode("\n", $row->params);
              if(!$params) $params = array();
              $comp[count($comp) + 1]->option="com_wrapper";
              $comp[count($comp)]->name="Wrapper";
              
              //$comp[count($comp) + 1]->option="com_search";
              //$comp[count($comp)]->name="Search";
              foreach($comp AS $com)
              {
                  
                  unset($param1,$param2);
                  if(in_array($com->option, $comps))
                  {
                      
                      foreach($params AS $param)
                      {
                          if(preg_match("/^".$com->option.":/iU", $param))
                          {
                              $param1[] = explode("=", @$param);
                              //$param1[] = explode("=", @$param);
                          }
                      }
                      $vis = 'visible';
                      $dis = "block";
                      $checked = ' checked="checked"';
                  }
                  else
                  {
                      $param1 = array();
                      $param2 = array();
                      $vis = 'hidden';
                      $dis = "none";
                      $checked = '';
                  }
                  ?>
                  <div>
                    <INPUT type="checkbox" <?php echo $checked; ?> id="check_<?php echo $com->option; ?>" onclick="jcsShowComParams('<?php echo $com->option ?>')" name="component[]" value="<?php echo $com->option ?>" /><?php echo $com->name ?>
                    <DIV id="params_<?php echo $com->option ?>" style="visibility: <?php echo $vis?>;display:<?php echo $dis?>;margin-left:20px;border:1px solid Silver; padding:10px">
                    Task: <INPUT value="<?php echo str_replace($com->option.":", "", $param1[0][0]) ?>" type="text" name="task_<?php echo $com->option ?>[]" class="inputbox" /> 
                    Value: <INPUT value="<?php echo $param1[0][1] ?>" type="text" name="value_<?php echo $com->option ?>[]" class="inputbox" /><BR>
        
                    Task: <INPUT value="<?php echo str_replace($com->option.":", "", $param1[1][0]) ?>" type="text" name="task_<?php echo $com->option ?>[]" class="inputbox" /> 
                    Value: <INPUT value="<?php echo $param1[1][1] ?>" type="text" name="value_<?php echo $com->option ?>[]" class="inputbox" /><BR>
        
                    </DIV> 
                  </div>             
                  <?php
              }
            ?>
          </td>
        </tr>
        
        <tr valign="top">
          <td colspan="2">Description:<BR><?php
        					// parameters : areaname, content, hidden field, width, height, rows, cols
        					editorArea( 'editor1', $row->description, 'description', '550', '200', '20', '25' ) ; ?></td>
        </tr>
        <tr valign="top">
          <td colspan="2"><BR><hr>Message that will be displayed after success subscription:<BR><?php
        					// parameters : areaname, content, hidden field, width, height, rows, cols
        					editorArea( 'editor2', $row->finish_msg, 'finish_msg', '550', '200', '20', '25' ) ; ?></td>
        </tr>
        </table>
            
    </TD>
    <TD width="45%">
      <?php    
      $tabs = new mosTabs(1);
      $tabs->startPane("Properties");
      $tabs->startTab( "Properties", "summaty-page" );
      ?>
        <table class="adminform">
        <tr>
          <td>Published:</td>
          <td>
            <INPUT type="checkbox" name="published" value="1" <?php if($row->published) echo " checked=checked"?>/> 
          </td>
        </tr>
        <tr>
          <td>Invisible:</td>
          <td>
            <INPUT type="checkbox" name="invisible" value="1" <?php if($row->invisible) echo " checked=checked"?>/> 
          </td>
        </tr>
        <tr>
          <td>Data Strict:</td>
          <td>
            <INPUT type="checkbox" name="data_fixed" value="1" <?php if($row->data_fixed) echo " checked=checked"?>/>
            <span class="small">If checked, user will be able to read only articles created whithin his subscription period and wount be able to read articles issued before.</span> 
          </td>
        </tr>
        <tr>
          <td>Grant:</td>
          <td>
            <INPUT type="checkbox" name="grant_reg" id="grant1" onclick="showCongrat();" value="Y" <?php if($row->grant_reg == 'Y') echo " checked=checked"?> name="gtoreg" /> <span class="small">Automaticly grant this subscription to all registered users.</span><BR>
            <INPUT type="checkbox" name="grant_new" id="grant2"  onclick="showCongrat();" value="Y" <?php if($row->grant_new == 'Y') echo " checked=checked"?>name="gtonewreg" /> <span class="small">Grant this subscription to all new users.</span><BR>
          </td>
        </tr>
        
        <tr valign="top">
          <td>Grant Congratulation page:</td>
          <td>
              <?php
                $query = "SELECT id, title, title_alias FROM `#__content` WHERE sectionid = 0 AND catid = 0";
                $database->setQuery( $query );
                $static = $database->loadObjectList();
                $stscontent[] = mosHTML::makeOption( '', 'None', 'id', 'status' );
                foreach($static AS $stat)
                {
                    $stscontent[] = mosHTML::makeOption( $stat->id, $stat->title.'/('.$stat->title_alias.')', 'id', 'status' );
                }
                echo mosHTML::selectList( $stscontent, 'granturl', 'class="inputbox" size="7"" ', 'id', 'status', $row->granturl);
              
              ?>
          </td>
        </tr>
        <tr>
          <td>Limit:</td>
          <td>
            <INPUT type="checkbox" name="one_time" value="1" <?php if($row->one_time) echo " checked=checked"?> /> User can subscribe this subscription only once 
          </td>
        </tr>
        <tr>
          <td>Alert Admin On Subscribe Event:</td>
          <td>
            <INPUT type="checkbox" name="alert_admin" value="1" <?php if($row->alert_admin) echo " checked=checked"?> /> 
          </td>
        </tr>
        <tr valign="top">
          <td>Assign Group:</td>
          <td><span class="warning" style="color: #ff0033;"><B>Attantion!!!!</B> Be very careful. If you set it to Registered and then set this subscription to Administrator you can lose controll over your site. If you do not need change users groups or you do not know what you are doing better skip this field.</span><BR>

            <?php echo $lists['gid']; ?> 
          </td>
        </tr>
        <tr valign="top">
          <td>Google AdWords Conversion Rate Code:</td>
          <td>
            <TEXTAREA name="adwords" cols="30" rows="5"><?php echo stripslashes($row->adwords) ?></TEXTAREA> 
          </td>
        </tr>
      </table>    
      <?php    
      $tabs->endTab();
      $tabs->endPane()
      ?>
    </TD>
  </TR>
</TABLE>

<INPUT type="hidden" name="id" value="<?php echo $cid;?>">
<input type="hidden" name="option" value="com_jcs" />
<input type="hidden" name="task" value="" /><?php //echo $task ?>
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="hidemainmenu" value="0" />
</form>
